﻿using System;
using System.Windows.Media.Effects;
using System.Windows;
using System.Windows.Media;

namespace SilverlightOverview
{
    public class SwirlEffect : ShaderEffect
    {
        private static PixelShader _pixelShader = new PixelShader()
                                                      {
                                                          UriSource = new Uri("SilverlightOverview;component/Swirl.ps",
                                                                              UriKind.Relative)
                                                      };

        public SwirlEffect()
        {
            PixelShader = _pixelShader;

            UpdateShaderValue(InputProperty);
            UpdateShaderValue(FactorProperty);
        }

        public static readonly DependencyProperty InputProperty =
            ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(SwirlEffect), 0);

        public Brush Input
        {
            get { return (Brush)GetValue(InputProperty); }
            set { SetValue(InputProperty, value); }
        }

        public static readonly DependencyProperty FactorProperty =
            DependencyProperty.Register("Factor",
                                        typeof(double), typeof(SwirlEffect),
                                        new PropertyMetadata(0.0, PixelShaderConstantCallback(0)));

        public double Factor
        {
            get { return (double)GetValue(FactorProperty); }
            set { SetValue(FactorProperty, value); }
        }
    }
}